package com.taiyuan.tongcheng.ui;

import org.kymjs.kjframe.utils.KJLoger;

import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

import cn.jpush.android.api.JPushInterface;

import com.taiyuan.tongcheng.ui.fragment.Fragment1;
import com.taiyuan.tongcheng.ui.fragment.Fragment2;
import com.taiyuan.tongcheng.ui.fragment.Fragment3;
import com.tytc56.user.R;

/**
 * 
* @Description 主activity
* @author wzq
* @date 2015-7-24 下午3:17:52
* @update (date)
* @version V1.0
 */
public class MainActivity extends FragmentActivity {
	/**
	 * FragmentTabhost
	 */
	private FragmentTabHost mTabHost;

	/**
	 * 布局填充器
	 */
	private LayoutInflater mLayoutInflater;

	/**
	 * Fragment数组界面
	 * 
	 */
	private Class mFragmentArray[] = { Fragment1.class, Fragment2.class,
			Fragment3.class};
	/**
	 * 存放图片数组
	 * 
	 */
	private int tabImgArray[] = { R.drawable.selector_bottombar_tab1,
			R.drawable.selector_bottombar_tab2, R.drawable.selector_bottombar_tab3};

	/**
	 * 选修卡文字
	 * 
	 */
	private String mTextArray[] = { "首页", "订单", "我的"};
	/**
	 * 
	 * 
	 */
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main_tab);

		initView();
		 KJLoger.debug("设备："+Build.MODEL+"RegistrationID="+JPushInterface.getRegistrationID(getApplicationContext()));
	}

	
	/**
	 * 初始化组件
	 */
	private void initView() {
		mLayoutInflater = LayoutInflater.from(this);
		// 找到TabHost
		mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
		mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
		// 得到fragment的个数
		int count = mFragmentArray.length;
		for (int i = 0; i < count; i++) {
			// 给每个Tab按钮设置图标、文字和内容
			TabSpec tabSpec = mTabHost.newTabSpec(mTextArray[i])
					.setIndicator(getTabItemView(i));
			// 将Tab按钮添加进Tab选项卡中
			mTabHost.addTab(tabSpec, mFragmentArray[i], null);
			// 设置Tab按钮的背景
		}
	}

	/**
	 *
	 * 给每个Tab按钮设置图标和文字
	 */
	private View getTabItemView(int index) {
		View view = mLayoutInflater.inflate(R.layout.layout_tab_item_view, null);
		ImageView imageView = (ImageView) view.findViewById(R.id.imageview);
		imageView.setImageResource(tabImgArray[index]);
		TextView textView = (TextView) view.findViewById(R.id.textview);
		textView.setText(mTextArray[index]);
		return view;
	}

}
